/*    */ package com.zimbra.cs.service.doc;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.MailConstants;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.mailbox.Document;
/*    */ import com.zimbra.cs.mailbox.MailItem.Type;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.OperationContext;
/*    */ import com.zimbra.cs.service.mail.ToXML;
/*    */ import com.zimbra.cs.service.util.ItemId;
/*    */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.HashSet;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class ListDocumentRevisions
/*    */   extends DocDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 41 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 42 */     Mailbox mbox = getRequestedMailbox(zsc);
/* 43 */     OperationContext octxt = getOperationContext(zsc, context);
/* 44 */     ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
/*    */     
/* 46 */     Element doc = request.getElement("doc");
/* 47 */     String id = doc.getAttribute("id");
/* 48 */     int version = (int)doc.getAttributeLong("ver", -1L);
/* 49 */     int count = (int)doc.getAttributeLong("count", 1L);
/*    */     
/* 51 */     Element response = zsc.createElement(MailConstants.LIST_DOCUMENT_REVISIONS_RESPONSE);
/*    */     
/*    */ 
/*    */ 
/* 55 */     ItemId iid = new ItemId(id, zsc);
/* 56 */     Document item = mbox.getDocumentById(octxt, iid.getId());
/*    */     
/* 58 */     if (version < 0) {
/* 59 */       version = item.getVersion();
/*    */     }
/* 61 */     MailItem.Type type = item.getType();
/* 62 */     HashSet<Account> accounts = new HashSet();
/* 63 */     Provisioning prov = Provisioning.getInstance();
/* 64 */     for (; (version > 0) && (count > 0); 
/*    */         
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/* 72 */         count--)
/*    */     {
/* 65 */       item = (Document)mbox.getItemRevision(octxt, iid.getId(), type, version);
/* 66 */       if (item != null) {
/* 67 */         ToXML.encodeDocument(response, ifmt, octxt, item);
/* 68 */         Account a = prov.getAccountByName(item.getCreator());
/* 69 */         if (a != null)
/* 70 */           accounts.add(a);
/*    */       }
/* 72 */       version--;
/*    */     }
/* 74 */     for (Account a : accounts) {
/* 75 */       Element user = response.addElement("user");
/* 76 */       user.addAttribute("id", a.getId());
/* 77 */       user.addAttribute("email", a.getName());
/* 78 */       user.addAttribute("name", a.getDisplayName());
/*    */     }
/*    */     
/* 81 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/doc/ListDocumentRevisions.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */